import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:honeypotflutter/modules/deliver/help/deliver_help.dart';
import 'package:honeypotflutter/publicBussine/bussine_colors.dart';
import 'package:honeypotflutter/publicBussine/bussine_font.dart';
import 'package:honeypotflutter/publicBussine/bussine_image.dart';
import 'package:honeypotflutter/publicBussine/view/bussine_card.dart';
import '../pages/deliver_select/logic.dart';

class DeliverSelectBoxInfo extends StatelessWidget {
  DeliverSelectBoxInfo({super.key});
  final DeliverSelectLogic _logic = Get.find<DeliverSelectLogic>();
  @override
  Widget build(BuildContext context) {
    return MGCard(
      margin: EdgeInsets.only(top: 16),
      children: [
        Container(
          width: double.infinity,
          child: Text(
            "选择格口",
            style: TextStyle(
              fontSize: MGFont.textFont1,
              color: MGColors.text1Color,
              fontWeight: FontWeight.bold,
            ),
          ),
        ),
        SizedBox(height: 15),
        Container(
          margin: EdgeInsets.only(bottom: 10),
          width: double.infinity,
          height: 340,
          child: Flex(
            direction: Axis.horizontal,
            children: [
              _oneBoxWidget(
                  imageName: "deliver_max_box",
                  child: GetBuilder<DeliverSelectLogic>(builder: (controller) {
                    return Column(
                      children: [
                        _priceWidget(
                          title: "大格口",
                          price: controller.infoModel.cabinetFee_s11,
                          color: "#FFFFFF",
                        ),
                        _countWidget(
                          color: MGColors.hexColor("#100558"),
                          public: controller.infoModel.largeNo,
                          rent: controller.infoModel.contractLargeNo,
                        ),
                      ],
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    );
                  }),
                  action: () {
                    _logic.pushToOrder(type: DeliverBoxType.max);
                  }),
              SizedBox(width: 10),
              Expanded(
                  child: Flex(
                direction: Axis.vertical,
                children: [
                  _oneBoxWidget(
                      imageName: "deliver_middle_box",
                      child: GetBuilder<DeliverSelectLogic>(builder: (controller) {
                        return Column(
                          children: [
                            _priceWidget(
                              title: "中格口",
                              price: controller.infoModel.cabinetFee_s12,
                              color: "#5B6EBA",
                            ),
                            _countWidget(
                              color: MGColors.hexColor("#5B6EBA"),
                              imageName: "deliver_middle_box_line",
                              public: controller.infoModel.largeNo,
                              rent: controller.infoModel.contractMediumNo,
                            ),
                          ],
                          mainAxisAlignment: MainAxisAlignment.spaceBetween,
                        );
                      }),
                      action: () {
                        _logic.pushToOrder(type: DeliverBoxType.middle);
                      }),
                  SizedBox(
                    height: 10,
                  ),
                  _oneBoxWidget(
                      imageName: "deliver_small_box",
                      child: GetBuilder<DeliverSelectLogic>(builder: (controller) {
                        return Column(
                          children: [
                            _priceWidget(
                              title: "小格口",
                              price: controller.infoModel.cabinetFee_s13,
                              color: "#238E9C",
                            ),
                            _countWidget(
                              color: MGColors.hexColor("#238E9C"),
                              imageName: "deliver_small_box_line",
                              public: controller.infoModel.smallNo,
                              rent: controller.infoModel.contractSmallNo,
                            ),
                          ],
                          mainAxisAlignment: MainAxisAlignment.spaceBetween,
                        );
                      }),
                      action: () {
                        _logic.pushToOrder(type: DeliverBoxType.small);
                      })
                ],
              )),
            ],
          ),
        )
      ],
    );
  }

  /*
  * 格口价格
  * */
  Widget _priceWidget({
    String title = "小格口",
    double? price,
    String color = "#238E9C",
  }) {
    return Column(
      children: [
        Text(title,
            style: TextStyle(
              color: MGColors.hexColor(color),
              fontSize: MGFont.titleFont4,
              fontWeight: FontWeight.bold,
            )),
        Text("(¥${price ?? 0.00})",
            style: TextStyle(
              color: MGColors.hexColor(color),
              fontSize: MGFont.textFont1,
            )),
      ],
    );
  }

  /*
  * 格口数量组件
  * */
  Widget _countWidget({
    Color color = Colors.white,
    int? public,
    int? rent,
    String imageName = "deliver_max_box_line",
  }) {
    return Row(
      children: [
        Text.rich(TextSpan(children: [
          TextSpan(
            text: (rent ?? 0.00).toString(),
            style: TextStyle(
              color: color,
              fontSize: MGFont.titleFont4,
              fontWeight: FontWeight.bold,
            ),
          ),
          TextSpan(
            text: "  租用",
            style: TextStyle(
              color: color,
              fontSize: MGFont.textFont3,
            ),
          )
        ])),
        Padding(
          padding: EdgeInsets.only(left: 8, right: 8),
          child: Image.asset(
            MGImage.image(imageName, type: ImagePathType.deliver),
            width: 3,
            height: 10,
          ),
        ),
        Text.rich(TextSpan(children: [
          TextSpan(
            text: (public ?? 0.00).toString(),
            style: TextStyle(
              color: color,
              fontSize: MGFont.titleFont4,
              fontWeight: FontWeight.bold,
            ),
          ),
          TextSpan(
            text: "  公用",
            style: TextStyle(
              color: color,
              fontSize: MGFont.textFont3,
            ),
          )
        ]))
      ],
      mainAxisAlignment: MainAxisAlignment.center,
    );
  }

  /*
  * 界面Widget
  * */
  Widget _oneBoxWidget({String? imageName, Function()? action, Widget? child}) {
    return Expanded(
        child: InkWell(
            child: Container(
                decoration: BoxDecoration(
                  image: DecorationImage(
                    image: AssetImage(MGImage.image(imageName ?? "", type: ImagePathType.deliver)),
                    fit: BoxFit.fill,
                  ),
                ),
                child: Container(
                  padding: EdgeInsets.all(16),
                  child: child,
                )),
            onTap: action));
  }
}
